export function removeLeafNodes(root: TreeNode | null, target: number): TreeNode | null {
  if (!root) return null;
  const fn = (node: TreeNode | null) => {
    if (!node) return null;
    node.left = fn(node.left);
    node.right = fn(node.right);
    if (!node.left && !node.right && node.val === target) {
      return null;
    }
    return node;
  };
  return fn(root);
}
